package com.mysql.work.algorithm;

import org.apache.shardingsphere.api.sharding.standard.PreciseShardingAlgorithm;
import org.apache.shardingsphere.api.sharding.standard.PreciseShardingValue;

import java.util.Collection;

public class MyPreciseShardingAlgorithm implements PreciseShardingAlgorithm<Integer> {
    @Override
    public String doSharding(Collection<String> collection, PreciseShardingValue<Integer> preciseShardingValue) {
        for(String ds:collection){
            if (ds.endsWith(preciseShardingValue.getValue() % collection.size() + "")) {
                return ds;
            }
        }
        throw new IllegalArgumentException();
    }
}
